﻿using System;
using System.Data;
using BLL;
using Ext.Net;

namespace ERP.Modules.Report
{
    public partial class ReportInventory : System.Web.UI.UserControl
    {
        readonly LockWarehouse_BLL clsLockWarehouse = new LockWarehouse_BLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                GetData();
            }
        }

        private void GetData()
        {
            StoreReportInventory.DataSource = clsLockWarehouse.BindGirdtb_LockWarehouse(string.Empty);
            StoreReportInventory.DataBind();
        }

        protected void ReportInventoryDblClick(object sender, DirectEventArgs e)
        {
            int ReportInventory_Id = int.Parse(e.ExtraParams["ReportInventory_ID"]);
            DataDetail(ReportInventory_Id);
            WindowsReportInventory.Show();
        }

        private void DataDetail(int reportInventoryId)
        {
            var dtLockWarehouse = clsLockWarehouse.BindGirdtb_LockWarehouseSelectRow(reportInventoryId);
            if (dtLockWarehouse != null && dtLockWarehouse.Rows.Count > 0)
            {
                txtReportInventory_ID.Text = dtLockWarehouse.Rows[0]["LockWarehouse_ID"].ToString();
                txtReportInventory_No.Text = dtLockWarehouse.Rows[0]["LockWarehouse_No"].ToString();
                txtReportInventory_Test.Text = dtLockWarehouse.Rows[0]["LockWarehouse_Test"].ToString();
                txtReportInventory_Note.Text = dtLockWarehouse.Rows[0]["LockWarehouse_Note"].ToString();
            }

            var clsLockWarehouseDetail = new LockWarehouse_Detail_BLL();
            StoreReportInventory_Detail.DataSource = clsLockWarehouseDetail.BindGirdtb_LockWarehouse_Detail(reportInventoryId);
            StoreReportInventory_Detail.DataBind();
        }

        protected void StoreReportInventory_RefreshData(object sender, StoreReadDataEventArgs e)
        {
            GetData();
        }

        protected void StoreReportInventory_Detail_RefreshData(object sender, StoreReadDataEventArgs e)
        {
            GetReportInventoryDetail();
        }

        protected void Lock_Click(object sender, DirectEventArgs e)
        {
            WindowsReportInventory.Show();
            GetReportInventoryDetail();
        }

        void GetReportInventoryDetail()
        {
            var cls = new LockWarehouse_BLL();
            StoreReportInventory_Detail.DataSource = cls.BindGirdtb_LockWarehouseDetail();
            StoreReportInventory_Detail.DataBind();
        }
    }
}